package cn.sinjet.myview;

import com.mgroup.wazehelper.R;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;
import cn.sinjet.entity.AppInfo;

public class MyShortcut extends FrameLayout{
	 public static final int FLAG_NONE = 0;
	 public static final int FLAG_CAR_APP = 1;
	 public static final int FLAG_THARD_APP = 2;
	 public static final int FLAG_ADD = 3;
	 private ImageView mImgView = null;  
	 private TextView mTextView = null;  
	 private ImageView mImgDelete = null;
	 private AppInfo mAppInfo = null;
	 boolean mIsDeleteMode = false;
	 int mFlag = FLAG_NONE;
	 String mText = "";
	 int mBackgroundResId = 0;
	 int mImageResId = 0;
	 Context context;
	public MyShortcut(Context context, AttributeSet attrs) {
		super(context, attrs);
		// TODO Auto-generated constructor stub
		 this.context = context;
		 LayoutInflater.from(context).inflate(R.layout.shortcut_view, this, true);
	     mImgView = (ImageView)findViewById(R.id.app_icon);  
	     mTextView = (TextView)findViewById(R.id.app_name);  
	     mImgDelete = (ImageView)findViewById(R.id.app_delete);
//	     
	}

	/*设置图片接口*/  
   public void setImageResource(int resId){
   	mImageResId = resId;
   }  
   public void setImageDrawable(Drawable drawable){
   	mImgView.setImageDrawable(drawable);
   }
   public void setAppInfo(AppInfo appInfo){
   	mAppInfo = appInfo;
   }
   
   
   public AppInfo getAppInfo(){
   	return mAppInfo;
   }
   
   /*设置文字接口*/  
   public void setText(String str){
   	mText = str;
   }  
   public void setFlag(int flag){
   	mFlag = flag;
   }
   public int getFlag(){
   	return mFlag;
   }
   public void setDeleteMode(boolean deleteMode){
   	mIsDeleteMode = deleteMode;
   }
   public boolean isDeleteMode(){
   	return mIsDeleteMode;
   }
   public void refresh(){
   	switch(mFlag){
   	case FLAG_ADD:
   		this.setBackgroundResource(R.drawable.btn_shortcut);
   		mImgView.setImageResource(R.drawable.ic_add_app);
   		mImgDelete.setVisibility(View.INVISIBLE);
   		mTextView.setText(context.getResources().getString(R.string.add_app));
   		break;
   	case FLAG_NONE:
   		mAppInfo = null;
   		this.setBackground(null);
   		mImgView.setImageDrawable(null);
   		mTextView.setText("");
   		mImgDelete.setVisibility(View.INVISIBLE);
   		break;
   	case FLAG_CAR_APP:
   		this.setBackgroundResource(R.drawable.btn_shortcut);
   		mImgDelete.setVisibility(View.INVISIBLE);
   		if(mImageResId != 0)
   		mImgView.setImageResource(mImageResId);
   		mTextView.setText(mText);
   		
   		break;
   	case FLAG_THARD_APP:
   		this.setBackgroundResource(R.drawable.btn_shortcut);
   		if(mAppInfo != null){
   			mImgView.setImageDrawable(mAppInfo.appIcon);
    	        mTextView.setText(mAppInfo.appName);
   		}
   		if(mIsDeleteMode) mImgDelete.setVisibility(View.VISIBLE);
   		else mImgDelete.setVisibility(View.INVISIBLE);
   		break;
   	}
   }
}
